﻿angular
    .module('paperless', [
        'ui.router', 'ngAnimate', 'ui.select2', 'chieffancypants.loadingBar',
        'restangular', 'ngTable',
        'mgcrea.ngStrap.tooltip', 'mgcrea.ngStrap.datepicker', 'mgcrea.ngStrap.modal', 'mgcrea.ngStrap.button', 'mgcrea.ngStrap.select',
        'ui.bootstrap.dropdownToggle', 'ui.bootstrap.collapse'])
    .config(function ($stateProvider, $urlRouterProvider, RestangularProvider, $datepickerProvider, $httpProvider) {
        $httpProvider.defaults.withCredentials = true;

        RestangularProvider
            .setBaseUrl('api/')
            .setErrorInterceptor(function (data) {
                console.log(data);
            })
            .addResponseInterceptor(function (responseData, operation, what, url, response) {
                var extractedData = responseData;

                if (operation === "getList") {
                    extractedData.total = parseInt(response.headers().total, 10);
                }

                return extractedData;
            });

        $urlRouterProvider.otherwise('/home');

        $stateProvider
            .state('home', {
                url: '/home',
                templateUrl: '/Scripts/app/views/home.html',
                controller: 'homeController'
            })
            .state('home2', {
                url: '/home2',
                templateUrl: '/Scripts/app/views/home.html',
                controller: 'home2Controller'
            })
             .state('transaction', {
                 url: '/transaction',
                 templateUrl: '/Scripts/app/views/transactions.html',
                 controller: 'transactionsController'
             })
             .state('transaction-view', {
                 url: '/transaction/view/:id',
                 templateUrl: '/Scripts/app/views/transaction-view.html',
                 controller: 'transactionViewController'
             })
             .state('transaction-edit', {
                 url: '/transaction/edit/:id',
                 templateUrl: '/Scripts/app/views/transaction-edit.html',
                 controller: 'transactionEditController'
             })
            .state('transaction-add', {
                url: '/transaction/edit',
                templateUrl: '/Scripts/app/views/transaction-edit.html',
                controller: 'transactionEditController'
            })
            .state('working', {
                url: '/working',
                templateUrl: '/Scripts/app/views/transaction.html',
                //controller: 'transactionController'
            })
            .state('tasks', {
                url: '/tasks',
                templateUrl: '/Scripts/app/views/transaction.html',
                //controller: 'transactionController'
            })
            .state('checklist', {
                url: '/checklist',
                templateUrl: '/Scripts/app/views/transaction.html',
                //controller: 'transactionController'
            });

        angular.extend($datepickerProvider.defaults, {
            dateFormat: 'MM/dd/yyyy',
            autoclose: true
        });
    });
